// Author: Ben
// Project: CR_RandomBackgroundChanger
// Path: C:\code\Abi\CR_RandomBackgroundChanger
// Creation date: 18.03.2008 15:31
// Last modified: 19.06.2008 12:48

#region Using directives
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
#endregion

namespace CR_RandomBackgroundChanger
{
	/// <summary>
	/// Random helper
	/// </summary>
	public class RandomHelper
	{
		#region Variables
		/// <summary>
		/// Last used random generator
		/// </summary>
		static Random lastUsedRandomGenerator = GetNewRandomGenerator();
		#endregion

		#region Properties
		/// <summary>
		/// Last used random generator
		/// </summary>
		/// <returns>Random</returns>
		public static Random LastUsedRandomGenerator
		{
			get
			{
				return lastUsedRandomGenerator;
			} // get
		} // LastUsedRandomGenerator
		#endregion

		#region Get new random generator
		/// <summary>
		/// Get new random generator with help of
		/// Win32Function.GetPerformanceCounter.
		/// </summary>
		/// <returns>Random</returns>
		public static Random GetNewRandomGenerator()
		{
			lastUsedRandomGenerator = new Random((int)DateTime.Now.Ticks);
			return lastUsedRandomGenerator;
		} // GetNewRandomGenerator()
		#endregion

		#region Get random int, float, byte, Vector and Color methods
		/// <summary>
		/// Get random int
		/// </summary>
		/// <param name="max">Maximum</param>
		/// <returns>Int</returns>
		public static int GetRandomInt(int max)
		{
			if (max <= 0)
				return 0;

			return LastUsedRandomGenerator.Next(max);
		} // GetRandomInt(max)

		/// <summary>
		/// Get random float between min and max
		/// </summary>
		/// <param name="min">Minimum</param>
		/// <param name="max">Maximum</param>
		/// <returns>Float</returns>
		public static float GetRandomFloat(float min, float max)
		{
			return (float)LastUsedRandomGenerator.NextDouble() * (max - min) + min;
		} // GetRandomFloat(min, max)
		#endregion
	} // class RandomHelper
} // namespace CR_RandomBackgroundChanger
